/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package libase.web.jsf.bean;

import java.util.List;
import javax.ejb.Stateless;
import javax.inject.Named;
import libase.entity.Reader;

/**
 *
 * @author aspr0
 */
@Named
@Stateless
public class ReaderBean extends AbstractBean
{
    private Reader r = new Reader();

    public Reader getR()
    {
        if (fetchId())
        {
            return r = em.find(Reader.class, id);
        }

        return r;
    }

    public void setR(Reader r)
    {
        this.r = r;
    }

    public List<Reader> getReaders()
    {
        return em.createNamedQuery("Reader.findAll").getResultList();
    }

    public void create()
    {
        em.persist(r);
        r = new Reader();
    }

    public void edit()
    {
        em.merge(r);
        r = new Reader();
    }

    public void remove()
    {
        getR();
        em.remove(r);
        r = new Reader();
    }
}
